Index: crypto/heimdal/appl/telnet/libtelnet/encrypt.c
===================================================================
--- crypto/heimdal/appl/telnet/libtelnet/encrypt.c	(revision 228798)
+++ crypto/heimdal/appl/telnet/libtelnet/encrypt.c	(working copy)
@@ -736,6 +736,9 @@
     int dir = kp->dir;
     int ret = 0;
 
+    if (len > MAXKEYLEN)
+        len = MAXKEYLEN;
+
     if (!(ep = (*kp->getcrypt)(*kp->modep))) {
 	if (len == 0)
 	    return;
Index: contrib/telnet/libtelnet/encrypt.c
===================================================================
--- contrib/telnet/libtelnet/encrypt.c	(revision 228798)
+++ contrib/telnet/libtelnet/encrypt.c	(working copy)
@@ -721,6 +721,9 @@
 	int dir = kp->dir;
 	int ret = 0;
 
+	if (len > MAXKEYLEN)
+		len = MAXKEYLEN;
+
 	if (!(ep = (*kp->getcrypt)(*kp->modep))) {
 		if (len == 0)
 			return;
